<?php

use Biz\model\store\StoreImagesModel;
use Hhzbeads\Img\ImageType;
use Hhzbeads\Img\ImgUrl;

ini_set('display_errors', 1);
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING ^ E_DEPRECATED);
ini_set('memory_limit', '1024M');

require_once '/data/wwwroot/g_vendor/autoload.php';


$start = microtime(true);
$page = 1;
$pageSize = 100;
$list = [];

do {
    $limit = [($page - 1) * $pageSize, $pageSize];
    //定时执行时间
    $where = [
        "LIMIT" => $limit,
        'check_status' => StoreImagesModel::DEFAULT
    ];
    $list = StoreImagesModel::all($where, ['id', 'store_id', 'check_status', 'img_id']);
    $pass_ids = [];
    $no_pass_ids = [];
    if ($list) {
        foreach ($list as $item) {
            try {
                $url = ImgUrl::getUrl(ImageType::APPTYPE_BIZ, $item['img_id'], ImageType::IMAGE_SIZE_SQ_BEST_PHONE);
//                $res = \Doraemon\service\ContentAudit\BaiDuPhoto::getAuditResultByUrl($url);
                $ali_rs = \Doraemon\service\ContentAudit\AliPicStrong::checkPic($url);
                if ($ali_rs['ret'] === true) {
                    $pass_ids[] = $item['id'];
                } else {
                    $no_pass_ids[] = $item['id'];
                }
            } catch (\Exception $e) {
                \Doraemon\tools\Log::cron_info('门店图片审核-error :' . $e->getMessage(), $item);
            }
        }
        var_dump('通过图片ids' . json_encode($pass_ids));
        $pass_where['id'] = $pass_ids;
        $pass_data['check_status'] = StoreImagesModel::PASS;
        $pass_data['updated_at'] = date('Y-m-d H:i:s');
        \Biz\model\store\StoreImagesModel::updated($pass_where, $pass_data);

        var_dump('未通过图片ids' . json_encode($no_pass_ids));
        $no_pass_where['id'] = $no_pass_ids;
        $un_pass_data['check_status'] = StoreImagesModel::UN_PASS;
        $un_pass_data['updated_at'] = date('Y-m-d H:i:s');
        \Biz\model\store\StoreImagesModel::updated($no_pass_where, $un_pass_data);
    }

    $page++;
} while ($list);

$end = microtime(true);
$time = $end - $start;
$second = round($time, 3);
var_dump('完成时间：' . date('Y-m-d H:i:s') . '   总耗时:' . $second . '秒');

